enyo.kind({
    name: "MyApps.News",
    kind: enyo.VFlexBox,
    events: {
        onBack: "",
    },
    components: [    /**
     * Services
     */
    {
        name: "getFeed",
        kind: "WebService",
        onSuccess: "gotFeed",
        onFailure: "gotFeedFailure",
    }, {
        name: "pane",
        kind: "Pane",
        flex: 1,
        transitionKind: "enyo.transitions.LeftRightFlyin",
        components: [{
            kind: "VFlexBox",
            components: [{
                kind: "PageHeader",
                className: "enyo-header-dark",
                components: [{
                    kind: "IconButton",
                    onclick: "doBack",
                    icon: "images/menu-icon-back.png",
                    className: "enyo-button-dark"
                }, {
                    kind: "VFlexBox",
                    flex: 1,
                    align: "center",
                    components: [{
                        content: "News"
                    }, ]
                }]
            }, {
                kind: "Scroller",
                flex: 1,
                className: "list",
                components: [{
                    name: "list",
                    kind: "VirtualRepeater",
                    onSetupRow: "getListItem",
                    components: [{
                        kind: "Item",
                        layoutKind: "VFlexLayout",
                        components: [{
                            name: "title",
                            kind: "Divider"
                        }, {
                            name: "description",
                            kind: "HtmlContent",
                            onLinkClick: "doLinkClick"
                        }],
                        onclick: "listItemClick"
                    }]
                }]
            }, {
                kind: "Image",
                src: "images/GolfZoneBanner.png",
                style: "padding-left: 0%"
            }, ]
        
        }, {
            name: "newsdetail",
            kind: "MyApps.Web",
            lazy: true,
            onBack: "goBack"
        }]
    }, ],
    
    
    create: function(){
        this.inherited(arguments);
        this.results = [];
        this.loadFeed();
    },
    goBack: function(inSender, inEvent){
        this.$.pane.back(inEvent);
    },
    
    loadFeed: function(){
        var url = "http://query.yahooapis.com/v1/public/yql?q=select%20" +
        "title%2C%20description%2C%20link%20from%20rss%20where%20url%3D%22" +
        "http://www.golf-zone.com/ninjarsssyndicator" +
        "%22&format=json&callback=";
        this.$.getFeed.setUrl(url);
        this.$.getFeed.call();
        
    },
    gotFeed: function(inSender, inResponse){
        this.results = inResponse.query.results.item;
        this.$.list.render();
    },
    gotFeedFailure: function(inSender, inResponse){
        console.log("failure from getFeed");
    },
    getListItem: function(inSender, inIndex){
        var r = this.results[inIndex];
        if (r) {
            this.$.title.setCaption(r.title);
            this.$.description.setContent(r.description);
            return true;
        }
    },
    listItemClick: function(inSender, inEvent){
        var feed = this.results[inEvent.rowIndex];
        this.$.pane.selectViewByName("newsdetail");
        this.$.newsdetail.setUrl(feed.link);
    },
    doLinkClick: function(inSender, inUrl){
        this.$.pane.selectViewByName("newsdetail");
        this.$.newsdetail.setUrl(inUrl);
    },
});

